#include <bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO
{ 
	char Is[(1<<21)+10],Os[(1<<21)+10];
	int Ipt,Opt;
	char gc()
	{
		if(Ipt==1<<21)Ipt=0;
		if(!Ipt){Is[fread(Is,1,1<<21,stdin)]=0;}
		return Is[Ipt++];
	}
	void flush(){fwrite(Os,1,Opt,stdout);Opt=0;}
	void pc(char x)
	{
		if(Opt==1<<21)flush();
		Os[Opt++]=x;
	}
	int read()
	{
		int x=0;char ch=gc();while(ch<'0'||ch>'9')ch=gc();while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=gc();return x;
	}
	void print(ll x){
		if(x<0) pc('-'),x=-x;
		if(x>9) print(x/10);
		pc('0'+x%10);
	}
	void print(__int128 x){
		if(x<0) pc('-'),x=-x;
		if(x>9) print(x/10);
		pc('0'+x%10);
	}
}
using namespace IO;

const int Maxn=2e6+7;
int c,T;
int n,k;
vector<ll>f[Maxn],smf[Maxn];

int a[Maxn],b[Maxn];
ll pos[Maxn],smb[Maxn];

int main(){
	freopen("festival.in","r",stdin);
	freopen("festival.out","w",stdout);
	
	cin>>c>>T;
	while(T--){
		cin>>n>>k;
		for(int i=1;i<n;i++) cin>>a[i]; 
		a[0]=a[1]; a[n]=a[n-1];
		for(int i=1;i<=k;i++) cin>>b[i];
		
		if(k==1){
			ll ans=0;
			pos[1]=a[1];
			for(int i=2;i<=n;i++){
				pos[i]=min(a[i-1]-pos[i-1],1ll*a[i]);
			}
			for(int i=1;i<=n;i++) ans+=pos[i];
			print((__int128)ans*b[1]); pc('\n');
			continue;
		}
		
		for(int i=0;i<=n;i++) f[i].resize(0),f[i].resize(a[i]+1),
							  smf[i].resize(0),smf[i].resize(a[i]+1);
		
		
		for(int i=1;i<=k;i++) smb[i]=smb[i-1]+b[i];
		for(int i=1;i<=n;i++){
			if(i<k) pos[i]=smb[i];
			else if(i>n-k) pos[i]=smb[k]-smb[i-(n-k)-1];
			else pos[i]=smb[k];
		}
		for(int i=1;i<=n;i++){
			for(int j=0;j<=min(a[i],a[i-1]);j++)
				f[i][j]=smf[i-1][a[i-1]-j]+pos[i]*j;
			smf[i][0]=f[i][0];
			for(int j=1;j<=a[i];j++)
				smf[i][j]=max(smf[i][j-1],f[i][j]);
		}
		print(smf[n][a[n]]); pc('\n');
	}
	
	flush();
	return 0;
}
/*
0 2
4 2
5 4 2
2 1
7 4
4 8 6 7 8 3
3 5 1 2


*/
